<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <el-input v-model="query.blurry" clearable size="small" placeholder="模糊搜索" style="width: 200px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <rrOperation />
      </div>
      <crudOperation :permission="permission" />
    </div>
    <!--表单组件-->
    <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="400px">
      <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
        <el-form-item label="姓名" prop="bisRyglXm">
          <el-input v-model="form.bisRyglXm" style="width: 250px;" />
        </el-form-item>
        <el-form-item label="性别" prop="bisRyglXb">
          <el-select v-model="form.bisRyglXb" filterable placeholder="请选择" style="width: 250px;">
            <el-option
              v-for="item in dict.xb"
              :key="item.id"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="证件类型" prop="bisRyglZjlx">
          <el-select v-model="form.bisRyglZjlx" filterable placeholder="请选择" style="width: 250px;">
            <el-option
              v-for="item in dict.zjlx"
              :key="item.id"
              aria-selected=""
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="身份证" prop="bisRyglZjhm">
          <el-input v-model="form.bisRyglZjhm" style="width: 250px;" />
        </el-form-item>
        <el-form-item label="联系电话" prop="bisRyglLxdh">
          <el-input v-model="form.bisRyglLxdh" style="width: 250px;" />
        </el-form-item>
        <el-form-item label="专家类别" prop="bisRyglZjlb">
          <el-select v-model="form.bisRyglZjlb" filterable placeholder="请选择" style="width: 250px;">
            <el-option
              v-for="item in dict.pgrylb"
              :key="item.id"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="简介">
          <el-input v-model="form.bisRyglJj" :rows="3" type="textarea" style="width: 250px;" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="text" @click="crud.cancelCU">取消</el-button>
        <el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
      </div>
    </el-dialog>
    <!--表格渲染-->
    <el-table
      ref="table"
      v-loading="crud.loading"
      :data="crud.data"
      size="small"
      style="width: 100%;"
      @selection-change="crud.selectionChangeHandler"
    >
      <el-table-column type="selection" width="55" />
      <el-table-column prop="bisRyglXm" label="姓名" />
      <el-table-column prop="bisRyglXb" label="性别">
        <template slot-scope="scope">
          {{ dict.label.xb[scope.row.bisRyglXb] }}
        </template>
      </el-table-column>
      <el-table-column prop="bisRyglLxdh" label="联系电话" />
      <el-table-column prop="bisRyglZjhm" label="身份证" />
      <el-table-column prop="bisRyglZjlb" label="专家类别">
        <template slot-scope="scope">
          {{ dict.label.pgrylb[scope.row.bisRyglZjlb] }}
        </template>
      </el-table-column>
      <el-table-column v-if="checkPer(['admin','pgry:edit','pgry:del'])" label="操作" width="150px" align="center">
        <template slot-scope="scope">
          <udOperation
            :data="scope.row"
            :permission="permission"
          />
        </template>
      </el-table-column>
    </el-table>
    <!--分页组件-->
    <pagination />
  </div>
</template>

<script>
import crudPgry from '@/api/business/pgry'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'

const defaultForm = { bisRyglId: null, bisRyglUserId: null, bisPggsId: null, bisRyglXm: null, bisRyglXb: null, bisRyglLxdh: null, bisRyglZjlx: '居民身份证', bisRyglZjhm: null, bisRyglJj: null, bisRyglYbqh: null, bisRyglYhdl: null, bisRyglKhhmc: null, bisRyglKhhid: null, bisRyglYhzh: null, bisRyglYhhm: null, bisRyglZjlb: null, bisRyglZjjszc: null, bisRyglXrzw: null, bisRyglZjks: null, bisRyglYzbm: null, bisRyglDzyx: null }
export default {
  name: 'Pgry',
  // eslint-disable-next-line vue/no-unused-components
  components: { pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  dicts: ['xb', 'rylx', 'pgrylb', 'zjlx'],
  cruds() {
    return CRUD({ title: '评估人员', url: 'api/pgry', idField: 'bisRyglId', sort: 'bisRyglId,desc', crudMethod: { ...crudPgry }})
  },
  data() {
    return {
      zjlx: '01',
      permission: {
        add: ['admin', 'pgry:add'],
        edit: ['admin', 'pgry:edit'],
        del: ['admin', 'pgry:del']
      },
      rules: {
        bisRyglXm: [
          { required: true, message: '姓名不能为空', trigger: 'blur' }
        ],
        bisRyglXb: [
          { required: true, message: '性别不能为空', trigger: 'blur' }
        ],
        bisRyglLxdh: [
          { required: true, message: '联系电话不能为空', trigger: 'blur' }
        ],
        bisRyglZjhm: [
          { required: true, message: '证件号码不能为空', trigger: 'blur' }
        ],
        bisRyglZjlb: [
          { required: true, message: '专家类别不能为空', trigger: 'blur' }
        ]
      },
      queryTypeOptions: [
        { key: 'bisRyglXm', display_name: '姓名' },
        { key: 'bisRyglXb', display_name: '性别' },
        { key: 'bisRyglLxdh', display_name: '联系电话' },
        { key: 'bisRyglZjhm', display_name: '证件号码' },
        { key: 'bisRyglZjlb', display_name: '专家类别' }
      ]
    }
  },
  created() {
    this.form.bisRyglZjlx = this.zjlx
    this.form.bisRyglZjhm = this.zjlx
    console.log(this.form.bisRyglZjlx)
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }
  }
}
</script>

<style scoped>

</style>
